package com.api.shopapi.mapper;


import com.api.shopapi.entity.Article;
import com.api.shopapi.entity.dto.ArticleDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ArticleMapper {

    @Insert("insert into  article " +
            "(" +
            "ArticleCode, " +
            "ArticleClassCode, " +
            "ArticleClassName, " +
            "Title, " +
            "Description, " +
            "Content, " +
            "CreateTime, " +
            "Status, " +
            "GovernmentCode, " +
            "FileUrl1, " +
            "FileUrl2, " +
            "FileUrl3, " +
            "StartTime, " +
            "EndTime, " +
            "JoinPeople" +
            ") VALUES " +
            "(" +
            "#{article.ArticleCode} ," +
            "#{article.ArticleClassCode} ," +
            "#{article.ArticleClassName} ," +
            "#{article.Title} ," +
            "#{article.Description} ," +
            "#{article.Content} ," +
            "#{article.CreateTime} ," +
            "#{article.Status} ," +
            "#{article.GovernmentCode} ," +
            "#{article.FileUrl1} ," +
            "#{article.FileUrl2} ," +
            "#{article.FileUrl3}, " +
            "#{article.StartTime}, " +
            "#{article.EndTime}," +
            "#{article.JoinPeople}" +
            ") ")
    int insert(@Param("article") Article article);



    @Update("update article set " +
            "ArticleCode=#{article.ArticleCode}," +
            "ArticleClassCode=#{article.ArticleClassCode}," +
            "ArticleClassName=#{article.ArticleClassName}," +
            "Title=#{article.Title}," +
            "Description=#{article.Description} ," +
            "Content=#{article.Content}," +
            "CreateTime=#{article.CreateTime}," +
            "Status=#{article.Status}," +
            "GovernmentCode=#{article.GovernmentCode} ," +
            "FileUrl1=#{article.FileUrl1} ," +
            "FileUrl2=#{article.FileUrl2} ," +
            "FileUrl3=#{article.FileUrl3} ," +
            "StartTime=#{article.StartTime} ," +
            "EndTime=#{article.EndTime}, " +
            "JoinPeople=#{article.JoinPeople} " +
            "where " +
            "ArticleCode=#{article.ArticleCode}      ")
    int update(@Param("article") Article article);


    @Select("select * from article where ArticleCode=#{articleCode} ")
    Article getByArticleCode(@Param("articleCode") String articleCode);

    @Select("<script>" +
            "select  * from article where GovernmentCode=#{governmentCode} " +
            "<if test ='title !=null and title!=\"\" '>" +
            "and Title like concat('%',#{title},'%') " +
            "</if>" +
            "<if test ='communityCode !=null and communityCode!=\"\" '>" +
            "and CommunityCode =#{communityCode} " +
            "</if>" +
            "<if test ='networkCode !=null and networkCode!=\"\" '>" +
            "and NetworkCode =#{networkCode} " +
            "</if>" +
            "<if test ='status != 0 '>" +
            "and Status = #{status} " +
            "</if>" +
            "<if test ='startTime !=null and startTime!=\"\" and endTime !=null and endTime!=\"\" '>" +
            "and StartTime between #{startTime} and #{endTime}" +
            "</if>" +
            "order by CreateTime desc " +
            "</script>")
    List<ArticleDTO> getPageList(@Param("governmentCode") String governmentCode, @Param("title") String title,
                                 @Param("status")int status, @Param("startTime")String startTime, @Param("endTime")String endTime,
                                 @Param("communityCode")String communityCode, @Param("networkCode")String networkCode);



    @Select("<script>" +
            "select * from article where GovernmentCode=#{governmentCode} " +
            " order by CreateTime desc " +
            "</script>")
    List<ArticleDTO> listByGovCode(@Param("governmentCode") String governmentCode);


}
